using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class DragPanel : MonoBehaviour, IDragHandler, IPointerDownHandler
{
    RectTransform rectTransform;
    Canvas canvas;
    void Awake()
    {
        rectTransform = GetComponent<RectTransform>();
        canvas = InventoryManager.Instance.GetComponent<Canvas>();
    }
    public void OnDrag(PointerEventData eventData)
    {
        // UI 的位置加上鼠标的移动向量  除以画布的缩放比例就得到屏幕距离了
        rectTransform.anchoredPosition += eventData.delta / canvas.scaleFactor;
    }

    public void OnPointerDown(PointerEventData eventData)
    {
        // 调整拖拽的面板的索引位置,确保正在点击拖拽的面板能遮挡另一个未拖拽的面板
        rectTransform.SetSiblingIndex(1);
    }
}
